﻿using NewsMine.FeedRepository;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using NewsMine.DomainObjects;
using System.Collections.Generic;
using FileBasedObjectRepository;

namespace FeedRepositoryTest
{
    
    
    /// <summary>
    ///This is a test class for FileBasedWebSiteStoreTest and is intended
    ///to contain all FileBasedWebSiteStoreTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FileBasedWebSiteStoreTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for FileBasedWebSiteStore Constructor
        ///</summary>
        [TestMethod()]
        public void FileBasedWebSiteStoreConstructorTest()
        {
            string rootFolder = @"c:\temp\Data";
            FileBasedWebSiteStore target = new FileBasedWebSiteStore(rootFolder);
        }

        /// <summary>
        ///A test for AddWebSiteInfo
        ///</summary>
        [TestMethod()]
        public void AddWebSiteInfoTest()
        {
            string rootFolder = @"c:\temp\Data";
            FileBasedWebSiteStore target = new FileBasedWebSiteStore(rootFolder); 
            WebSiteInfo webSiteInfo = new WebSiteInfo { };
            WebSiteInfo actual = target.AddWebSiteInfo(webSiteInfo);
            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.ID > 0);
        }

        /// <summary>
        ///A test for GetAllWebSites
        ///</summary>
        [TestMethod()]
        public void GetAllWebSitesTest()
        {
            string rootFolder = @"c:\temp\Data";
            FileBasedWebSiteStore target = new FileBasedWebSiteStore(rootFolder); 
            var result  = target.GetAllWebSites();
            Assert.IsTrue(result.Count>7);
        }

        /// <summary>
        ///A test for GetWebSiteByDomain
        ///</summary>
        [TestMethod()]
        public void GetWebSiteByDomainTest()
        {
            string rootFolder = @"c:\temp\Data";
            FileBasedWebSiteStore target = new FileBasedWebSiteStore(rootFolder); // TODO: Initialize to an appropriate value
            WebSiteInfo webSiteInfo = new WebSiteInfo {Domain="test.com" };
            WebSiteInfo actual = target.AddWebSiteInfo(webSiteInfo);
            Assert.IsTrue(actual.ID > 0);

            var result  = target.GetWebSiteByDomain("test.com");
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count > 0);
            Assert.IsTrue(result[0].Domain.ToLower().Contains("test.com"));
        }


        /// <summary>
        ///A test for GetWebSitesByLauguage
        ///</summary>
        [TestMethod()]
        public void GetWebSitesByLauguageTest()
        {
            string rootFolder = @"c:\temp\Data";
            FileBasedWebSiteStore target = new FileBasedWebSiteStore(rootFolder); // TODO: Initialize to an appropriate value
            WebSiteInfo webSiteInfo = new WebSiteInfo { Domain = "test.com",Language="en" };
            WebSiteInfo actual = target.AddWebSiteInfo(webSiteInfo);
            Assert.IsTrue(actual.ID > 0);
            var result = target.GetWebSitesByLauguage("en");
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count > 0);
            Assert.IsTrue(result[0].Domain.ToLower().Contains("test.com"));
            Assert.IsTrue(result[0].Language.ToLower().Contains("en"));
        }

        /// <summary>
        ///A test for ReadDataFromCSVFiles
        ///</summary>
        [TestMethod()]
        public void ReadDataFromCSVFilesTest()
        {
            string rootFolder = string.Empty; // TODO: Initialize to an appropriate value
            FileBasedWebSiteStore target = new FileBasedWebSiteStore(rootFolder); // TODO: Initialize to an appropriate value
            target.ReadDataFromCSVFiles();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        /// <summary>
        ///A test for SaveWebSiteInfo
        ///</summary>
        [TestMethod()]
        public void SaveWebSiteInfoTest()
        {
            string rootFolder = string.Empty; // TODO: Initialize to an appropriate value
            FileBasedWebSiteStore target = new FileBasedWebSiteStore(rootFolder); // TODO: Initialize to an appropriate value
            WebSiteInfo webSiteInfo = null; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.SaveWebSiteInfo(webSiteInfo);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        /// <summary>
        ///A test for webSiteRepository
        ///</summary>
        [TestMethod()]
        [DeploymentItem("NewsMine.FeedRepository.dll")]
        public void webSiteRepositoryTest()
        {
            PrivateObject param0 = null; // TODO: Initialize to an appropriate value
            FileBasedWebSiteStore_Accessor target = new FileBasedWebSiteStore_Accessor(param0); // TODO: Initialize to an appropriate value
            GenericFileDataStore<WebSiteInfo> expected = null; // TODO: Initialize to an appropriate value
            GenericFileDataStore<WebSiteInfo> actual;
            target.webSiteRepository = expected;
            actual = target.webSiteRepository;
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
    }
}
